package vip.zhenzicheng.rabbitmq.workqueue;

import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import vip.zhenzicheng.rabbitmq.utils.RabbitConstant;
import vip.zhenzicheng.rabbitmq.utils.RabbitUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author zhenzicheng
 * @DESCRIPTION: 工作队列模式demo 模拟订单系统
 * @DATE: 2022/04/24 3:11 PM
 */
public class OrderSystem {
  public static void main(String[] args) throws IOException, TimeoutException {
    Connection conn = RabbitUtils.getConnection();
    Channel channel = conn.createChannel();
    channel.queueDeclare(RabbitConstant.QUEUE_SMS, false, false, false, null);

    for (int i = 1; i <= 100; i++) {
      SMS sms = new SMS("乘客" + i, "13900000" + i, "您的车票已预订成功");
      String jsonSMS = new Gson().toJson(sms);
      channel.basicPublish("", RabbitConstant.QUEUE_SMS, null, jsonSMS.getBytes());
    }
    System.out.println("发送数据成功！");
    channel.close();
    conn.close();
  }
}
